package com.scalar.chiptrack.rma.forms;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.ChipTrackActionForm;
import com.scalar.chiptrack.rma.RMALineItem;
import com.scalar.chiptrack.utils.AutoGrowingArrayList;
import com.scalar.chiptrack.commons.Address;

import java.util.HashMap;
import java.util.ArrayList;

public final class RMAForm extends ChipTrackActionForm
{

    private int rmaId           = -1;
    private int customerId      = -1;
    private int billingAddressId= -1;
    private int clientAddressId = -1;
    private int endUserID       = -1;
    private int vendorId        = -1;

    private String customerName     = null;
    private String rmaNumber        = null;
    private String contactPerson    = null;
    private String salesPerson      = null;
    private String phoneNumber      = null;
    private String faxNumber        = null;
    private String email            = null;
    private String shipVia          = null;
    private String billingAddress   = null;
    private String comments         = null;
    private String status           = null;
    private String enteredBy        = null;
    private String rmaRequestDate   = null;
    private String rmaIssueDate     = null;
    private String rmaExpirationDate = null;
    private String rmaStatus        = null;
    private String clientAddress    = null;
    private String approvedStatus   = null;

    private String address1 = null;
    private String address2 = null;
    private String address3 = null;
    private String address4 = null;

    private String city         = null;
    private String state        = null;
    private String zipcode      = null;
    private String country      = null;
    private String closeDate    = null;
    private String endUser      = null;

    private String vendorAddressString  = null;

    private HashMap vendorAddressMap    = null;

    private Address vendorAddressObject = null;

    private ArrayList lineItemList = new AutoGrowingArrayList(RMALineItem.class);

    /**
     * @return customerName
     */
    public String getCustomerName() {

	return (this.customerName);

    }

    /**
     * Set the customername
     *
     * @param customerName
     */
    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    /**
     * @return rmaNumber
     */
    public String getRmaNumber() {
		return (this.rmaNumber);
    }

    /**
     * Set the rmaNumber
     *
     * @param rmaNumber
     */
    public void setRmaNumber(String rmaNumber) {
        this.rmaNumber = rmaNumber;
    }

	public int getRmaId(){
		return rmaId;
	}

	public void setRmaId(int rmaId){
		this.rmaId = rmaId;
	}

	public int getCustomerId(){
		return customerId;
	}

	public void setCustomerId(int customerId){
		this.customerId = customerId;
	}

	public String getContactPerson(){
		return contactPerson;
	}

	public void setContactPerson(String contactPerson){
		this.contactPerson = contactPerson;
	}

	public String getSalesPerson(){
		return salesPerson;
	}

	public void setSalesPerson(String salesPerson){
		this.salesPerson = salesPerson;
	}

	public String getPhoneNumber(){
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber){
		this.phoneNumber = phoneNumber;
	}

	public String getFaxNumber(){
		return faxNumber;
	}

	public void setFaxNumber(String faxNumber){
		this.faxNumber = faxNumber ;
	}

	public String getEmail(){
		return email;
	}

	public void setEmail(String email){
		this.email = email;
	}

	public String getShipVia(){
		return shipVia;
	}

	public void setShipVia(String shipVia){
		this.shipVia = shipVia;
	}

	public int getBillingAddressId(){
		return billingAddressId;
	}

	public void setBillingAddressId(int billingAddressId){
		this.billingAddressId = billingAddressId;
	}

	public String getBillingAddress(){
		return billingAddress;
	}

	public void setBillingAddress(String billingAddress){
		this.billingAddress = billingAddress;
	}

	public String getComments(){
		return comments;
	}

	public void setComments(String comments){
		this.comments = comments;
	}

	public String getStatus(){
		return status;
	}

	public void setStatus(String status){
		this.status = status;
	}

	public String getEnteredBy(){
		return enteredBy;
	}

	public void setEnteredBy(String enteredBy){
		this.enteredBy = enteredBy ;
	}

	public String getRmaRequestDate(){
		return rmaRequestDate;
	}

	public void setRmaRequestDate(String rmaRequestDate){
		this.rmaRequestDate = rmaRequestDate;
	}

	public String getRmaIssueDate(){
		return rmaIssueDate;
	}

	public void setRmaIssueDate(String rmaIssueDate){
		this.rmaIssueDate = rmaIssueDate;
	}

	public String getRmaExpirationDate(){
		return rmaExpirationDate;
	}

	public void setrmaExpirationDate(String rmaExpirationDate){
		this.rmaExpirationDate = rmaExpirationDate;
	}
	
	public String getRmaStatus(){
		return rmaStatus;
	}
	public void setRmaStatus(String rmaStatus){
		this.rmaStatus = rmaStatus;
	}
	
	public int getClientAddressId(){
		return clientAddressId;
	}
	
	public void setclientAddressId(int clientAddressId){
		this.clientAddressId = clientAddressId;
	}
	
	public String getClientAddress(){
		return clientAddress;
	}
	public void setClientAddress(String clientAddress){
		this.clientAddress = clientAddress;
	}
	
	public String getAddress1(){
		return address1;
	}
	public void setAddress1(String address1){
		this.address1 = address1;
	}
	
	public String getAddress2(){
		return address2;
	}
	public void setAddress2(String address2){
		this.address2 = address2;
	}
	
	public String getAddress3(){
		return address3;
	}
	public void setAddress3(String address3){
		this.address3 = address3;
	}

    public String getAddress4(){
		return address4;
	}
	public void setAddress4(String address4){
		this.address4 = address4;
	}

	public String getCity(){
		return city;
	}
	public void setCity(String city){
		this.city = city;
	}
	
	public String getState(){
		return state;
	}
	public void setState(String state){
		this.state = state;
	}
	
	public String getCountry(){
		return country;
	}
	
	public void setCountry(String country){
		this.country = country;
	}
	
	public String getZipcode(){
		return zipcode;
	}
	
	public void setZipcode(String zipcode){
		this.zipcode = zipcode;
	}
	public String getCloseDate(){
		return closeDate;
	}
	
	public void setCloseDate(String closeDate){
		this.closeDate = closeDate;
	}

    public String getEndUser(){
		return endUser;
	}

	public void setEndUser(String endUser){
		this.endUser = endUser;
	}

    public int getEndUserID() {
        return endUserID;
    }

    public void setEndUserID(int endUserID) {
        this.endUserID = endUserID;
    }


    public String getVendorAddressString()
    {           
        return vendorAddressString;
    }

    public void setVendorAddressString(String vendorAddressString)
    {
        this.vendorAddressString = vendorAddressString;
    }

    public int getVendorId()
    {
        return vendorId;
    }

    public void setVendorId(int vendorId)
    {
        this.vendorId = vendorId;
    }

    public HashMap getVendorAddressMap()
    {
        return vendorAddressMap;
    }

    public void setVendorAddressMap(HashMap vendorAddressMap)
    {
        this.vendorAddressMap = vendorAddressMap;
    }


    public Address getVendorAddressObject()
    {
        return vendorAddressObject;
    }

    public void setVendorAddressObject(Address vendorAddressObject)
    {
        this.vendorAddressObject = vendorAddressObject;
    }

    public String getAddressAsString ()
    {
        StringBuffer tempAddress = new StringBuffer ( "" );
        if ( !( customerName.equals ( contactPerson ) ) )
        {
            if ( contactPerson != null && !( contactPerson.trim ().equals ( "" ) ) )
            {
                tempAddress.append ( contactPerson + "\n" );
            }
        }
        if ( address1 != null && !( address1.trim ().equals ( "" ) ) && !(address1.equals(customerName ) ) )
        {
            tempAddress.append ( address1 + "\n" );
        }
        if ( address2 != null && !( address2.equals ( "" ) ) )
        {
            tempAddress.append ( address2 + "\n" );
        }
        if ( address3 != null && !( address3.equals ( "" ) ) )
        {
            tempAddress.append ( address3 + "\n" );
        }
        if ( address4 != null && !( address4.equals ( "" ) ) )
        {
            tempAddress.append ( address4 + "\n" );
        }
        if ( city != null && !( city.equals ( "" ) ) )
        {
            tempAddress.append ( city + "\n" );
        }
        if ( state != null && !( state.equals ( "" ) ) )
        {
            tempAddress.append ( state );
        }
        if ( zipcode != null && !( zipcode.equals ( "" ) ) )
        {
            if ( state != null && !( state.equals ( "" ) ) )
            {
                tempAddress.append ( " - " );
            }
            tempAddress.append ( zipcode );
        }
        if ( country != null && !( country.equals ( "" ) ) )
        {
            if ( ( zipcode != null && !( zipcode.equals ( "" ) ) ) || ( state != null && !( state.equals ( "" ) ) ) )
            {
                tempAddress.append ( ", " );
            }
            tempAddress.append ( country + "\n" );
        }
        tempAddress.append ( phoneNumber != null && !( phoneNumber.equals ( "" ) ) ? "\n\nTel:" + phoneNumber : "" );
        tempAddress.append ( faxNumber != null && !( faxNumber.equals ( "" ) ) ? "\nFax:" + faxNumber : "" );
        tempAddress.append ( email != null && !( email.equals ( "" ) ) ? "\nEmail:" + email : "" );
        return tempAddress.toString ();
    }


    public String getApprovedStatus() {
        return approvedStatus;
    }

    public void setApprovedStatus(String approvedStatus) {
        this.approvedStatus = approvedStatus;
    }


    public ArrayList getLineItemList() {
        return lineItemList;
    }

    public void setLineItemList(ArrayList lineItemList) {
        this.lineItemList = lineItemList;
    }

    public String getAddressAsHTML ()
    {
        StringBuffer tempAddress = new StringBuffer ( "" );
        String address = getAddressAsString ();
        if (address != null)
        {
        for ( int i = 0; i < address.length (); i++ )
        {
            char ch = address.charAt ( i );
            if ( ch == '\n' )
            {
                tempAddress.append ( "<br>" );
            }
            else
            {
                tempAddress.append ( ch );
            }
        }
        }
        return tempAddress.toString ();
    }
    public String getVendorAddressAsHTML ()
    {
        StringBuffer tempAddress = new StringBuffer ( "" );
        String address = getVendorAddressString ();
        if ( address != null )
        {
            for ( int i = 0; i < address.length (); i++ )
            {
                char ch = address.charAt ( i );
                if ( ch == '\n' )
                {
                    tempAddress.append ( "<br>" );
                }
                else
                {
                    tempAddress.append ( ch );
                }
            }
        }
        return tempAddress.toString ();
    }
    /**
     * Reset all properties to their default values.
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     */
     
    public void reset(ActionMapping mapping, HttpServletRequest request) {

        this.customerName = null;
		this.rmaNumber = null;
    }

    /**
     * Validate the properties that have been set from this HTTP request,
     * and return an <code>ActionErrors</code> object that encapsulates any
     * validation errors that have been found.  If no errors are found, return
     * <code>null</code> or an <code>ActionErrors</code> object with no
     * recorded error messages.
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     */
    public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();
        return errors;
    }

}
